﻿using System;
using System.Collections;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Web;
using System.Web.SessionState;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.HtmlControls;

using BEGDC.CC.BL.Common;
using BEGDC.Utility.Castle;
using BEGDC.CC.BL.Common.Query;
using BEGDC.CC.Entity;

namespace BEGDC.CC.Web.Common
{
    /// <summary>
    /// Summary description for AssignApp.
    /// </summary>
    public class AssignAppForOCO : System.Web.UI.Page
    {
        protected System.Web.UI.WebControls.Label lblStaff;
        protected System.Web.UI.WebControls.Button btnAssign;
        protected System.Web.UI.WebControls.DropDownList ddlCODStaff;
        protected System.Web.UI.HtmlControls.HtmlTableCell txtHint;
        protected System.Web.UI.WebControls.RadioButtonList rbSSMEEVPApprove;
        protected System.Web.UI.WebControls.Button ibtnClose;
        protected System.Web.UI.HtmlControls.HtmlTableRow tr_chooseStaff;

        private void Page_Load(object sender, System.EventArgs e)
        {
            // Put user code to initialize the page here
            if (!IsPostBack)
            {
                //this.btnAssign.Attributes["onclick"] = "javascript:OnAssign();";
                this.btnAssign.Attributes.Add("onclick", "javascript:OnAssign();");
                BindCODStaff();

                if (Request.QueryString["IsSSME"].ToUpper() == "TRUE")
                    this.rbSSMEEVPApprove.Enabled = true;
                else if (Request.QueryString["IsSSME"].ToUpper() == "FALSE")
                    this.rbSSMEEVPApprove.Enabled = false;

                if (Request.QueryString["IsCheck"] == "Y")
                    this.tr_chooseStaff.Visible = false;

                //if (Convert.ToInt32(Request.QueryString["appid"]) > 0)
                //{
                //    if (this.PaymentMoney(Convert.ToInt32(Request.QueryString["appid"])))
                //    {
                //        this.txtHint.InnerHtml = "&nbsp;&nbsp;由于金额大于10000元，根据公司规定必须由IBG Head进行审批!";
                //        this.rbSSMEEVPApprove.SelectedValue = "1";
                //        this.rbSSMEEVPApprove.Enabled = false;
                //    }
                //}
                //else
                //{
                //    this.btnAssign.Enabled = true;
                //}

                //if (decimal.Parse(Request.QueryString["Total"]) > 0)
                //{
                //    if (this.PaymentMoney(decimal.Parse(Request.QueryString["Total"])))
                //    {
                //        this.txtHint.InnerHtml = "The Application will need IBG Head to approve for its estimated total cost greater than 10,000 yuan.<br/> 由于申请金额大于10000元，需由IBG HEAD进行审批! ";
                //        this.rbSSMEEVPApprove.SelectedValue = "1";
                //        this.rbSSMEEVPApprove.Enabled = false;
                //    }
                //}
                //else
                //{
                //    this.btnAssign.Enabled = true;
                //}
            }
        }

        //private bool PaymentMoney(decimal total)
        //{
        //    //get Estimated Total Cost 
        //    //IQuery queryService = AppContainer.Instance[ServiceConst.QueryService] as IQuery;
        //    //PaymentInfo paymentInfo = queryService.GetPaymentInfo(total);
        //    //decimal estimatedTotalCost = paymentInfo.DecryptedEstimatedCustomerTotalCost;
        //    if (decimal.Parse(cilsearch.GetRMBValueFromEuroValue(1)) * total > 10000)
        //    {
        //        return true;
        //    }
        //    else
        //    {
        //        return false;
        //    }
        //}


        #region Web Form Designer generated code
        override protected void OnInit(EventArgs e)
        {
            //
            // CODEGEN: This call is required by the ASP.NET Web Form Designer.
            //
            InitializeComponent();
            base.OnInit(e);
        }

        /// <summary>
        /// Required method for Designer support - do not modify
        /// the contents of this method with the code editor.
        /// </summary>
        private void InitializeComponent()
        {
            this.btnAssign.Click += new EventHandler(btnAssign_Click);
            this.ibtnClose.Click += new EventHandler(ibtnClose_Click);
            this.Load += new System.EventHandler(this.Page_Load);

        }
        #endregion

        private void BindCODStaff()
        {
            BEGDC.CC.BL.Common.IUtility utility = AppContainer.Instance[ServiceConst.UtilityService] as BEGDC.CC.BL.Common.IUtility;
            DataTable table = null;
            if (Request.QueryString["IsFilter"] == null || Request.QueryString["IsFilter"] == "true")
            {
                table = utility.GetOCOStaffByAppID(Convert.ToInt32(Request.QueryString["AppID"]), true);
            }
            else
            {
                table = utility.GetOCOStaffByAppID(Convert.ToInt32(Request.QueryString["AppID"]), false);
            }

            if (table == null || table.Rows.Count == 0)
            {
                this.txtHint.InnerHtml = "There aren't any ICOStaffs. If you want to assign the request, please contact role admin to add one.<br/> 不存在ICO职员，如果您想指派当前申请，请联系角色管理员.";
            }
            else
            {
                this.ddlCODStaff.DataSource = table;
                this.ddlCODStaff.DataValueField = "EmployeeNo";
                this.ddlCODStaff.DataTextField = "NameEN";
                this.ddlCODStaff.DataBind();
            }
        }

        void btnAssign_Click(object sender, EventArgs e)
        {
            string str = this.ddlCODStaff.SelectedValue;
            string str1 = this.rbSSMEEVPApprove.SelectedItem.Text;
            Response.Write(@"<Script>returnValue='" + this.ddlCODStaff.SelectedValue + "_" + this.rbSSMEEVPApprove.SelectedItem.Text + "';window.close(); </Script>");
        }

        void ibtnClose_Click(object sender, EventArgs e)
        {
            Response.Write(@"<Script>returnValue='%close%';self.close(); </Script>");
        }
    }
}
